package com.itheima.stock.controller;

import com.itheima.stock.pojo.SysPermission;
import com.itheima.stock.service.PreService;
import com.itheima.stock.vo.req.PerReq;
import com.itheima.stock.vo.resp.PerEveName;
import com.itheima.stock.vo.resp.R;
import com.itheima.stock.vo.resp.TianJiaRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class PerController {

    @Autowired
    private PreService preService;

    //查询权限的数据
    @GetMapping("/permissions")
    public R<List<SysPermission>> getPer() {
        R<List<SysPermission>> all = preService.findAll();
        return all;
    }

    //权限添加按钮
    @PostMapping("/permission")
    public R<TianJiaRes> addPer(@RequestBody PerReq perReq) {
       R<TianJiaRes> tianJiaResR = preService.addPer(perReq);
       return tianJiaResR;
    }


    //权限的更新操作
    @PutMapping("/permission")
    public R<TianJiaRes> updatePer(@RequestBody PerReq perReq) {
        R<TianJiaRes> tianJiaResR = preService.updatePer(perReq);
        return tianJiaResR;
    }


    //权限删除操作
    @DeleteMapping("/permission/{permissionId}")
    public R<TianJiaRes> deletePer(@PathVariable String permissionId) {
        R<TianJiaRes> tianJiaResR = preService.upDeletePer(permissionId);
        return tianJiaResR;
    }

    //权限回显
    @GetMapping("/permissions/tree")
    public R<List<PerEveName>> getPerEveName() {
        R<List<PerEveName>> perEveName = preService.findPerEveName();
        return perEveName;
    }



}
